package com.nuhu.dao;

import com.nuhu.pojo.ComplaintRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ComplaintRecordDao {
    @Insert("INSERT INTO  complaint_record (issue_type, issue_details, issue_resolved, phone_number, signed_status, rating)" +
            "VALUES (#{issueType}, #{issueDetails}, 0, #{phoneNumber}, 0, 0)")
    void insertComplaintRecord(ComplaintRecord complaintRecord);

    @Update("UPDATE complaint_record\n" +
            "SET Rating = TRUE, Issue_Resolved = TRUE\n" +
            "WHERE Phone_Number = #{phoneNumber}")
    void complaintSetIssueResolved(ComplaintRecord complaintRecord);

    @Select("SELECT Rating, Issue_Resolved\n" +
            "FROM complaint_record\n" +
            "WHERE Phone_Number = #{phoneNumber}")
    ComplaintRecord complaintGetIssueResolved(ComplaintRecord complaintRecord);

    @Update("UPDATE complaint_record\n" +
            "SET Signed_Status = TRUE\n" +
            "WHERE Phone_Number = #{phoneNumber};")
    void complaintSetIsSigned(ComplaintRecord complaintRecord);

    @Select("SELECT Signed_Status\n" +
            "FROM complaint_record\n" +
            "WHERE Phone_Number = #{phoneNumber}")
    ComplaintRecord complaintGetIsSigned(ComplaintRecord complaintRecord);

    @Select("SELECT Issue_Type, Issue_Details, Phone_Number\n" +
            "FROM complaint_record\n" +
            "ORDER BY Issue_Type DESC\n" +
            "LIMIT 1;")
        ComplaintRecord selectComplaintRecord();
}
